﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI.Export;
using Telerik.WinControls.UI;
using Telerik.WinControls;

namespace ChopPlugin
{
    public partial class DlgRefCheck : Telerik.WinControls.UI.RadForm
    {
        public DlgRefCheck()
        {
            InitializeComponent();
        }

        public void BindSource(List<ReferenceDiagnostic> diagList)
        {
            radGridView.DataSource  = diagList;
            radGridView.EnableFiltering = true;
            radGridView.MasterTemplate.Columns["Source"].Width = 80;
            radGridView.MasterTemplate.Columns["Reference"].Width = 80;
            radGridView.MasterTemplate.Columns["AnnotText"].Width = 400;
            radGridView.MasterTemplate.Columns["Type"].TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
        }

        #region Excel export

        private void radButtonExport_Click(object sender, EventArgs e)
        {

            RunExportToExcelML();
        }

        /// <summary> Export Grid to Excel </summary>
        private void RunExportToExcelML()
        {
            ExportToExcelML excelExporter = null;
            try
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                excelExporter = new ExportToExcelML(this.radGridView);

                excelExporter.SummariesExportOption = SummariesOption.ExportAll;
                //set export settings
                excelExporter.ExportVisualSettings = false;
                excelExporter.ExportHierarchy = true;
                excelExporter.HiddenColumnOption = HiddenOption.DoNotExport;

                this.Cursor = Cursors.WaitCursor;
                saveFileDialog.Filter = UcChop.EXCEL_FILTER;
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    excelExporter.RunExport(saveFileDialog.FileName);

                    DialogResult dr = RadMessageBox.Show(UcChop.MSG_EXPORT_SUCCESS,
                       UcChop.EXPORT_CAPTION, MessageBoxButtons.YesNo, RadMessageIcon.Question);
                    if (dr == DialogResult.Yes)
                    {
                        System.Diagnostics.Process.Start(saveFileDialog.FileName);
                    }
                }
            }
            catch (Exception ex)
            {
                RadMessageBox.Show(this, ex.Message, UcChop.ERR_CAPTION, MessageBoxButtons.OK, RadMessageIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;

            }
        }


        #endregion

    }
}
